package interfaces;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import services.User;
import controller.AlarmClockController;
import controller.DataEditorController;
import controller.SleepChartController;


public class MainFrame extends JFrame {

	private static final long serialVersionUID = 1L;

	private JTabbedPane pane;
	private static User user;
	public MainFrame(User u) {
		super();
		user = u;
		setTitle("Менеджер сна");
		setSize(500,500);
		setLocationRelativeTo(null);
		initComponents();
	}
	
	private void initComponents() {
		JPanel panel = new JPanel(new BorderLayout());
		pane = new JTabbedPane();
		panel.add(pane);
		getContentPane().add(panel);
		
		pane.addTab("Работа с данными", new DataEditor(new DataEditorController()));
		pane.addTab("Графическоке представление", new SleepChartPanel(new SleepChartController()));
		pane.addTab("Будильник", new AlarmClockEditor(new AlarmClockController()));
		if(user != null) 
			addAdditionalComponents();
		pack();
	}
	
	private void addMenuBar() {
		JMenuBar bar = new JMenuBar();
		JMenu bdMenu = new JMenu("Взаимодействие с БД");
		bdMenu.add(new JMenuItem("Восстановление данных из БД"));
		bdMenu.add(new JMenuItem("Синхронизация с БД"));
		JMenu forecastMenu = new JMenu("Прогнозирование");
		JMenuItem jMenuItem = new JMenuItem("Прогноз");
		jMenuItem.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
//				ForecastDialog.showDialog(MainFrame.getUser());
			}
		});
		forecastMenu.add(jMenuItem);
		bar.add(bdMenu);
		bar.add(forecastMenu);
		setJMenuBar(bar);
	}

	private void addAdditionalComponents() {
		addMenuBar();
	}
	
	public static User getUser() {
		return user;
	}
}
